package ysf.com.mediumdifficulty;

/**
 * @author ysf
 * @date 2021/6/22 22:02
 */
public class EleventhDemo {

    public static void main(String[] args) {

        int[] input = new int[]{1,8,6,2,5,4,8,3,7};
        /*int maxArea = maxAreas(input);
        System.out.println(maxArea);*/

        int[] inputs = new int[]{2,8,6,2,5,4,8,3};
        int maxAreas = maxAreas(inputs);
        System.out.println(maxAreas);
    }

    /*private static int maxArea(int[] height){
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = i+1; j < height.length; j++) {
                int h = Math.min(height[i],height[j]);
                if (h * (j - i) > max){
                    max = h* (j-i);
                }
            }
        }
        return max;
    }*/

    private static int maxAreas(int[] height){
        int maxarea = 0, left = 0, right = height.length - 1;
        while (left<right){
            int minarea = Math.min(height[left],height[right])*(right - left);
            maxarea = Math.max(maxarea,minarea);
            if (height[left] < height[right]){
                left ++;
            }else {
                right --;
            }
        }
        return maxarea;

    }










}
